<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>编辑信息</title>
    <link rel="stylesheet" href="../css/page-health-orderInfo.css"/>
    <link rel="stylesheet" href="../plugins/elementui/index.css"/>
    <script src="../plugins/jquery/dist/jquery.min.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../plugins/datapicker/datePicker.js"></script>
    <script src="../plugins/vue/vue.js"></script>
    <script src="../plugins/vue/axios-0.18.0.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script>
        var id = getUrlParam("id");
    </script>
</head>
<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
<div id="app" class="app">
    <!-- 页面头部 -->
    <div class="top-header">
        <span class="f-left"><i class="icon-back" onclick="history.go(-1)"></i></span>
        <span class="center">修改密码</span>
        <span class="f-right"><i class="icon-more"></i></span>
    </div>
    <!-- 页面内容 -->
    <div class="contentBox">
        <div class="form-info">
            <!--验证表单区域-->
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="新密码" prop="password">
                    <el-input v-model="ruleForm.password"></el-input>
                </el-form-item>

                <el-form-item label="确认新密码" prop="senPassword">
                    <el-input v-model="ruleForm.senPassword"></el-input>
                </el-form-item>

                <!--提交和返回按钮-->
                <el-form-item>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <el-button @click="resetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</div>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            //表单的双向数据绑定
            ruleForm: {
                //新密码
                password: '',
                //确认新密码
                senPassword: ''
            },

            //校验规则
            rules: {
                password: [
                    {required: true, message: '请输入密码', trigger: 'blur'},
                    {min: 6, message: '密码最少需要6位', trigger: 'blur'}
                ],
                senPassword: [
                    {required: true, message: '请输入密码', trigger: 'change'},
                    {min: 6, message: '密码最少需要6位', trigger: 'blur'}
                ],
            },

        },

        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    //如果用户两次输入的密码不一致，给出提示信息(密码为空这里不做判断)
                    if (this.ruleForm.password===this.ruleForm.senPassword) {
                    }else {
                        //如果两次输入的密码不一致
                        this.$message.error("两次密码输入不一致");
                        return;
                    }

                    if (valid) {
                        //用户输入了新密码，且新密码的长度大于6，且两次输入的密码一致
                        //获取请求路径中的该用户的id
                        let memberId = getUrlParam("memberId");

                        //向后端发送修改密码的请求
                        axios.post("/member/editPassword.do?memberId=" + memberId,this.ruleForm).then((response) => {
                            if (response.data.flag) {
                                //修改密码成功
                                this.$message({
                                    type: 'success',
                                    message: response.data.message
                                });

                                //跳转到登录界面，这个时候cookie、session已经清除了,但是要把邮箱带过去用于数据回显
                                window.location.href = "/pages/login.html?email="+response.data.data;

                            } else {
                                //密码修改失败
                                this.$message.error(response.data.message);
                            }
                        });
                    } else {
                        //用户没有输入密码，或密码长度不符合要求
                        this.$message.error("密码格式错误!");
                        return false;
                    }
                });
            },
        }
    });
</script>
</body>
</html>